package com.eling.elcms.travel.model;

import com.eling.elcms.basedoc.model.PersonalInfo;
import com.eling.elcms.cater.model.ConsumeCard;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.travel.model.RoomPerConsumption.ConsumptionType;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;

import javax.persistence.*;
import java.util.Set;

/**
 * 入住房间人员
 * @author wulina
 *
 */
@Entity
@Table(name = "travel_roompersonalInfo")
@Indexed
public class RoomPersonalInfo extends BaseModel {

	private static final long serialVersionUID = 3275300060956221991L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@DocumentId
	@In
	private Long pkRoomPersonalInfo;
	
	/** 入住准备落实 */
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
	@JoinColumn(name = "pkCIImplement")
	@IndexedEmbedded(depth = 1)
	private CheckInImplement checkInImplement;

	/** 房间登记 */
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
	@JoinColumn(name = "pkRoomRegister")
	@IndexedEmbedded(depth = 1)
	private RoomRegister roomRegister;

	/** 报名人员*老人团 */
	@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
	@JoinColumn(name = "pkSignUpRegister")
	@IndexedEmbedded(depth = 1)
	//TODO 待修改为老人团对报名人员的中间关联
	private SignUpRegister signUpRegister;
	
	/** 报名人员*散客 */
	@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
	@JoinColumn(name = "pkNonMemberRegister")
	@IndexedEmbedded(depth = 1)
	private NonMemberRegister nonMemberRegister;
	
	/** 人员信息 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkPersonalInfo")
	@IndexedEmbedded(depth = 1)
	private PersonalInfo personalInfo;
	
	/** 消费卡 */
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkConsumeCard")
	@IndexedEmbedded(depth = 1)
	private ConsumeCard consumeCard;
	
	/** 人员-房间消费情况 */
	@OneToMany(fetch = FetchType.LAZY)
	@IndexedEmbedded(depth = 1)
	@JoinColumn(name = "pkRoomPersonalInfo")
	private Set<RoomPerConsumption> roomPerConsumptions;
	
	/** 人员消费信息 */
	@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
	@JoinColumn(name = "pkCheckOutSettlement")
	@IndexedEmbedded(depth = 1)
	private CheckOutSettlement checkOutSettlement;	
	
	/** 是否登记 */
	@Column
	@Field
	private Boolean checkIn;

	@Version
	private Integer version;
	
	/** 换房消费*/
	@Column
	private Double changeRoomFee;
	
	/** 备注*/
	@Column
	private String descript;
	
	/** 计算房内消费*/
	public Double getRoomConsumption(){
		Double roomConsumption = 0.00;
		if(roomPerConsumptions == null || roomPerConsumptions.size() == 0){
			return roomConsumption;
		}else{
			for(RoomPerConsumption roomPerConsumption : roomPerConsumptions){
				if(roomPerConsumption.getConsumptionType().equals(ConsumptionType.RoomConsumption)){
					roomConsumption += roomPerConsumption.getPrice() * roomPerConsumption.getNum();
				}
			}
			return roomConsumption;
		}
	}
	
	/** 计算赔偿费*/
	public Double getDamagesConsumption(){
		Double roomConsumption = 0.00;
		if(roomPerConsumptions == null || roomPerConsumptions.size() == 0){
			return roomConsumption;
		}else{
			for(RoomPerConsumption roomPerConsumption : roomPerConsumptions){
				if(roomPerConsumption.getConsumptionType().equals(ConsumptionType.DamageConsumption)){
					roomConsumption += roomPerConsumption.getPrice() * roomPerConsumption.getNum();
				}
			}
			return roomConsumption;
		}
	}

	public Long getPkRoomPersonalInfo() {
		return pkRoomPersonalInfo;
	}

	public void setPkRoomPersonalInfo(Long pkRoomPersonalInfo) {
		this.pkRoomPersonalInfo = pkRoomPersonalInfo;
	}

	public RoomRegister getRoomRegister() {
		return roomRegister;
	}

	public void setRoomRegister(RoomRegister roomRegister) {
		this.roomRegister = roomRegister;
	}

	public SignUpRegister getSignUpRegister() {
		return signUpRegister;
	}

	public void setSignUpRegister(SignUpRegister signUpRegister) {
		this.signUpRegister = signUpRegister;
	}

	public NonMemberRegister getNonMemberRegister() {
		return nonMemberRegister;
	}

	public void setNonMemberRegister(NonMemberRegister nonMemberRegister) {
		this.nonMemberRegister = nonMemberRegister;
	}

	public PersonalInfo getPersonalInfo() {
		return personalInfo;
	}

	public void setPersonalInfo(PersonalInfo personalInfo) {
		this.personalInfo = personalInfo;
	}

	public ConsumeCard getConsumeCard() {
		return consumeCard;
	}

	public void setConsumeCard(ConsumeCard consumeCard) {
		this.consumeCard = consumeCard;
	}

	public Set<RoomPerConsumption> getRoomPerConsumptions() {
		return roomPerConsumptions;
	}

	public void setRoomPerConsumptions(Set<RoomPerConsumption> roomPerConsumptions) {
		this.roomPerConsumptions = roomPerConsumptions;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public Double getChangeRoomFee() {
		return changeRoomFee;
	}

	public void setChangeRoomFee(Double changeRoomFee) {
		this.changeRoomFee = changeRoomFee;
	}

	public CheckInImplement getCheckInImplement() {
		return checkInImplement;
	}

	public void setCheckInImplement(CheckInImplement checkInImplement) {
		this.checkInImplement = checkInImplement;
	}

	public Boolean getCheckIn() {
		return checkIn;
	}

	public CheckOutSettlement getCheckOutSettlement() {
		return checkOutSettlement;
	}

	public void setCheckOutSettlement(CheckOutSettlement checkOutSettlement) {
		this.checkOutSettlement = checkOutSettlement;
	}

	public void setCheckIn(Boolean checkIn) {
		this.checkIn = checkIn;
	}

	public String getDescript() {
		return descript;
	}

	public void setDescript(String descript) {
		this.descript = descript;
	}
	
}
